const Sequelize = require("sequelize");
const sequelize = require("./../utils/db");

const User = sequelize.define('base_user',{
	id:{type:Sequelize.INTEGER,field:"id",primaryKey:true},
	username:{type:Sequelize.STRING,field:"username"},
	account:{type:Sequelize.STRING,field:"account"},
	mobile:{type:Sequelize.STRING,field:"mobile"},
	userType:{type:Sequelize.STRING,field:"user_type"},

},{
	freezeTableName:true,
	timestamps: false
});

//const user = User.sync({force:false});

exports.addUser = (user) => {
	return User.create(user);
};

exports.findByUsername = (userName) => {
	return User.findOne({where:{username:userName}});
};

exports.findAll = (params)=>{
	return User.findAll(params);
};

exports.findOrsByAccount = (account) => {
//	return sequelize.query("SELECT * FROM base_user WHERE  account=:account",{replacements:{"account":account},model:User,type: sequelize.QueryTypes.SELECT})

return sequelize.query("SELECT * FROM base_user WHERE  account=:account",{replacements:{"account":account},type: sequelize.QueryTypes.SELECT})
}
